package com.xbongbong.paas.service.impl;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.xbongbong.formula.service.FunctionService;
import com.xbongbong.paas.constant.MessageConstant;
import com.xbongbong.paas.constant.PaasConstant;
import com.xbongbong.paas.domain.entity.PaasFormEntity;
import com.xbongbong.paas.domain.entity.PaasFormExplainEntity;
import com.xbongbong.paas.enums.DelEnum;
import com.xbongbong.paas.enums.FieldTypeEnum;
import com.xbongbong.paas.field.FieldAttrEntity;
import com.xbongbong.paas.field.FormulaPoJo;
import com.xbongbong.paas.help.ConditionListHelp;
import com.xbongbong.paas.help.ProFormHelp;
import com.xbongbong.paas.service.FormulaService;
import com.xbongbong.paas.toolbox.exception.XbbException;
import com.xbongbong.paas.toolbox.helper.GaodeGeoHelper;
import com.xbongbong.paas.toolbox.util.CollectionsUtil;
import com.xbongbong.paas.toolbox.util.DateTimeUtil;
import com.xbongbong.paas.toolbox.util.RegexUtil;
import com.xbongbong.paas.util.ExplainUtil;
import com.xbongbong.paas.util.WorkflowUtil;
import com.xbongbong.parent.condition.ProConditionHelp;
import com.xbongbong.pro.constant.BusinessConstant;
import com.xbongbong.pro.enums.errorcodes.ProErrorCodeEnum;
import com.xbongbong.pro.enums.errorcodes.SystemErrorCodeEnum;
import com.xbongbong.pro.form.pojo.RuleTargetPojo;
import com.xbongbong.pro.formula.pojo.dto.FormulaDTO;
import com.xbongbong.pro.formula.pojo.dto.ValidateFormulaDTO;
import com.xbongbong.pro.formula.pojo.dto.WorkflowValidateFormulaDTO;
import com.xbongbong.pro.formula.pojo.vo.FormulaVO;
import com.xbongbong.pro.formula.pojo.vo.ValidateFormulaVO;
import com.xbongbong.pro.formula.pojo.vo.WorkflowValidateFormulaVO;
import com.xbongbong.saas.constant.BasicConstant;
import com.xbongbong.saas.constant.StringConstant;
import com.xbongbong.saas.enums.XbbRefTypeEnum;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Set;

/**
 * @author 吴峰
 * @version v1.0
 * @date 2019/5/30 11:21
 * @since v1.0
 */
@Service("formulaService")
public class FormulaServiceImpl implements FormulaService {

    private static final Logger LOGGER = LoggerFactory.getLogger(FormulaServiceImpl.class);

    @Resource
    private FunctionService functionService;
    @Resource
    private ProFormHelp proFormHelp;
    @Resource
    private ProConditionHelp proConditionHelp;


    @Override
    public FormulaVO formulaCalculate(FormulaDTO formulaDTO) throws XbbException {
        FormulaVO formulaVO = new FormulaVO();
        try {
            Object result = functionService.expressRunValue(formulaDTO.getFormula());
            formulaVO.setOutcome(result);
        } catch (Exception e) {
            throw new XbbException(SystemErrorCodeEnum.API_ERROR_100001);
        }
        return formulaVO;
    }


    @Override
    public ValidateFormulaVO validate(ValidateFormulaDTO validateFormulaDTO) throws XbbException {
        ValidateFormulaVO validateFormulaVO = new ValidateFormulaVO();
        String corpid = validateFormulaDTO.getCorpid();
        RuleTargetPojo ruleTargetPojo = validateFormulaDTO.getRuleTarget();
        Long formId = validateFormulaDTO.getFormId();
        Integer businessType = validateFormulaDTO.getBusinessType();
        try {
            PaasFormExplainEntity thisExplain = proFormHelp.getExplainEntity(corpid, validateFormulaDTO.getFormId(), validateFormulaDTO.getBusinessType());
            PaasFormExplainEntity targetExplain = proFormHelp.getExplainEntity(corpid, ruleTargetPojo.getFormId(), ruleTargetPojo.getLinkBusinessType());
            // 字段解释
            Map<String, FieldAttrEntity> thisExplainMap = ExplainUtil.getExplainMap(thisExplain.getExplains(), null);
            ProFormHelp.setDataIdAttr(thisExplainMap);
            Map<String, FieldAttrEntity> targetExplainMap = ExplainUtil.getExplainMap(targetExplain.getExplains(), null);
            ProFormHelp.setDataIdAttr(targetExplainMap);

            Map<String, FieldAttrEntity> thisSubExplainMap = new HashMap<>(PaasConstant.DEFAULT_INITIAL_CAPACITY);
            Map<String, FieldAttrEntity> targetSubExplainMap = new HashMap<>(PaasConstant.DEFAULT_INITIAL_CAPACITY);
            String targetAttr = validateFormulaDTO.getAttr();
            List<String> targetFieldList = ExplainUtil.getAttrByPoint(targetAttr);
            FieldAttrEntity targetField;
            if (targetFieldList.size() == 2) {
                targetAttr = targetFieldList.get(0);
                String targetSubAttr = targetFieldList.get(1);
                FieldAttrEntity fieldAttrEntity = targetExplainMap.get(targetAttr);
                targetSubExplainMap = ExplainUtil.getExplainMapByList(fieldAttrEntity.getSubForm().getItems());
                targetField = targetSubExplainMap.get(targetSubAttr);
            } else {
                targetField = targetExplainMap.get(targetAttr);
            }
            FormulaPoJo formulaPoJo = validateFormulaDTO.getFormula();
            String formula = formulaPoJo.getFormula();
            String[] formulaArray = RegexUtil.getFormulaAttr(formula);
            List<Integer> fieldList = Arrays.asList(FieldTypeEnum.LINK_DATA.getType(), FieldTypeEnum.LINK_DATA_MULTI.getType());
            if (fieldList.contains(validateFormulaDTO.getFieldType()) && formulaArray.length != 1) {
                throw new XbbException(ProErrorCodeEnum.API_ERROR_260016);
            }
            for (int i = 0; i < formulaArray.length; i++) {
                String formulaAttr = formulaArray[i];
                Object value = "";
                String attr = "";
                if (formulaAttr.contains("self.")) {
                    // 本表单的字段操作
                    attr = formulaAttr.replaceAll("self.", "").replaceAll("[\\{\\}]", "");
                    value = getValue(attr, thisExplainMap, thisSubExplainMap, targetField, formId, ruleTargetPojo, businessType);
                } else if (RegexUtil.isStartWithNumber(formulaAttr) || formulaAttr.contains("workOrder_")) {
                    // 目标表单
                    Integer startNum = formulaAttr.indexOf(".")+1;
                    Integer length = formulaAttr.length();
                    attr = formulaAttr.substring(startNum, length).replaceAll("[\\{\\}]", "");
                    value = getValue(attr, targetExplainMap, targetSubExplainMap, targetField, formId, ruleTargetPojo, businessType);
                } else if (formulaAttr.contains("user.")) {
                    value = formulaAttr.replace("user.", "").replaceAll("[\\{\\}]", "");
                    value = "\"" + value + "\"";
                }else if (formulaAttr.contains("dept.")) {
                    value = formulaAttr.replace("dept.", "").replaceAll("[\\{\\}]", "");
                }
                formula = formula.replace(formulaAttr, value.toString());
            }
            Object result = validateDataType(formula, validateFormulaDTO.getFieldType());
            validateFormulaVO.setResult(result);
        } catch (XbbException e) {
            throw e;
        } catch (Exception e) {
            LOGGER.error("formulaServiceImpl.validate出错：", e);
            throw new XbbException(SystemErrorCodeEnum.API_ERROR_100001);
        }
        return validateFormulaVO;
    }


    @Override
    public WorkflowValidateFormulaVO workflowValidate(WorkflowValidateFormulaDTO workflowValidateFormulaDTO) throws XbbException {
        WorkflowValidateFormulaVO validateFormulaVO = new WorkflowValidateFormulaVO();
        String corpid = workflowValidateFormulaDTO.getCorpid();

        try {
            FormulaPoJo formulaPoJo = workflowValidateFormulaDTO.getFormula();
            String formula = formulaPoJo.getFormula();
            String[] formulaArray = RegexUtil.getFormulaAttr(formula);
            List<Integer> fieldList = Arrays.asList(FieldTypeEnum.LINK_DATA.getType(), FieldTypeEnum.LINK_DATA_MULTI.getType());
            if (fieldList.contains(workflowValidateFormulaDTO.getFieldType()) && formulaArray.length != 1) {
                throw new XbbException(ProErrorCodeEnum.API_ERROR_260016);
            }
            Set<Long> formIdSet = new HashSet<>();
            Set<Long> workOrderFormIdSet = new HashSet<>();
            Map<String, String> subFormMap = new HashMap<>(PaasConstant.DEFAULT_INITIAL_CAPACITY);
            for (int i = 0; i < formulaArray.length; i++) {
                String formulaStr = formulaArray[i];
                String[] list = WorkflowUtil.getAttrByFormula(formulaStr);
                if (formulaStr.contains(FieldTypeEnum.SUB_FORM.getEsalias())) {
                    if (formulaStr.contains(XbbRefTypeEnum.WORK_ORDER.getAlias())) {
                        Long formId = Long.valueOf(list[2].replace(XbbRefTypeEnum.WORK_ORDER.getAlias() + StringConstant.UNDER_LINE, ""));
                        workOrderFormIdSet.add(formId);
                        subFormMap.put(list[2], list[3]);
                    } else {
                        Long formId = Long.valueOf(list[2]);
                        formIdSet.add(formId);
                        subFormMap.put(list[2], list[3]);
                    }
                } else if (WorkflowUtil.validateFormula(list, formulaStr)){
                    if (formulaStr.contains(XbbRefTypeEnum.WORK_ORDER.getAlias())) {
                        Long formId = Long.valueOf(list[2].replace(XbbRefTypeEnum.WORK_ORDER.getAlias() + StringConstant.UNDER_LINE, ""));
                        workOrderFormIdSet.add(formId);
                    } else {
                        Long formId = Long.valueOf(list[2]);
                        formIdSet.add(formId);
                    }

                }
            }
            Long targetFormId = workflowValidateFormulaDTO.getFormId();
            Integer targetBusinessType = workflowValidateFormulaDTO.getBusinessType();
            if (Objects.equals(XbbRefTypeEnum.WORK_ORDER.getCode(), targetBusinessType)) {
                workOrderFormIdSet.add(targetFormId);
            } else {
                formIdSet.add(targetFormId);
            }
            Map<Long, Map<String, FieldAttrEntity>> explainMap = proFormHelp.getFormFieldMap(formIdSet, corpid);
            Map<Long, Map<String, FieldAttrEntity>> workOrderFormFieldMap = proFormHelp.getWorkOrderFormFieldMap(workOrderFormIdSet, corpid);
            Map<Long, PaasFormEntity> formMap = proFormHelp.getFormMap(formIdSet, corpid, DelEnum.NORMAL.getDel());
            // 字段解释
            // {"表单id或者workOrder_表单id":{"子表单attr": {"子表单内字段attr": {字段属性:字段属性值}}}}
            // {"表单id或者workOrder_表单id":{"子表单attr": {"子表单内字段attr": {字段属性:字段属性值}}}}
            Map<String, Map<String, Map<String, FieldAttrEntity>>> thisSubExplainMap = new HashMap<>(PaasConstant.DEFAULT_INITIAL_CAPACITY);
            if (!subFormMap.isEmpty()) {
                for (Map.Entry<String, String> entry : subFormMap.entrySet()) {
                    String key = entry.getKey();
                    String value = entry.getValue();
                    FieldAttrEntity fieldAttrEntity;
                    if (key.contains(XbbRefTypeEnum.WORK_ORDER.getAlias())) {
                        Long workOrderFormId = Long.valueOf(key.replace(XbbRefTypeEnum.WORK_ORDER.getAlias() + StringConstant.UNDER_LINE, ""));
                        fieldAttrEntity = workOrderFormFieldMap.get(workOrderFormId).get(value);
                    } else {
                        fieldAttrEntity = explainMap.get(Long.valueOf(key)).get(value);
                    }
                    if (Objects.isNull(fieldAttrEntity)) {
                        throw new XbbException(SystemErrorCodeEnum.API_ERROR_100001, MessageConstant.THIS_FIELD_TYPE_NOT_EXIST);
                    }
                    List<? extends FieldAttrEntity> subFieldList = fieldAttrEntity.getSubForm().getItems();
                    Map<String, Map<String, FieldAttrEntity>> subMap = new HashMap<>(BasicConstant.ONE);
                    subMap.put(value, ExplainUtil.getExplainMapByList(subFieldList));
                    thisSubExplainMap.put(key, subMap);
                }
            }
            String targetAttr = workflowValidateFormulaDTO.getAttr();
            List<String> targetFieldList = ExplainUtil.getAttrByPoint(targetAttr);
            FieldAttrEntity targetField;
            if (targetFieldList.size() == 2) {
                FieldAttrEntity fieldAttrEntity;
                targetAttr = targetFieldList.get(0);
                if (Objects.equals(XbbRefTypeEnum.WORK_ORDER.getCode(), targetBusinessType)) {
                    fieldAttrEntity = workOrderFormFieldMap.get(targetFormId).get(targetAttr);
                } else {
                    fieldAttrEntity = explainMap.get(targetFormId).get(targetAttr);
                }
                if (Objects.isNull(fieldAttrEntity)) {
                    throw new XbbException(SystemErrorCodeEnum.API_ERROR_100001, MessageConstant.THIS_FIELD_TYPE_NOT_EXIST);
                }
                List<? extends FieldAttrEntity> subFieldList = fieldAttrEntity.getSubForm().getItems();

                String targetSubAttr = targetFieldList.get(1);
                targetField =  ExplainUtil.getExplainMapByList(subFieldList).get(targetSubAttr);
            } else {
                if (Objects.equals(XbbRefTypeEnum.WORK_ORDER.getCode(), targetBusinessType)) {
                   targetField = workOrderFormFieldMap.get(targetFormId).get(targetAttr);
                } else {
                    targetField = explainMap.get(targetFormId).get(targetAttr);
                }
            }
            if (Objects.isNull(targetField)) {
                throw new XbbException(SystemErrorCodeEnum.API_ERROR_100001, MessageConstant.THIS_FIELD_TYPE_NOT_EXIST);
            }
            for (int i = 0; i < formulaArray.length; i++) {
                String formulaStr = formulaArray[i];
                String[] list = WorkflowUtil.getAttrByFormula(formulaStr);
                Object value = "";
                if (formulaStr.contains(FieldTypeEnum.SUB_FORM.getEsalias())) {
                    if (formulaStr.contains(XbbRefTypeEnum.WORK_ORDER.getAlias())) {
                        Long workOrderFormId = Long.valueOf(list[2].replace(XbbRefTypeEnum.WORK_ORDER.getAlias() + StringConstant.UNDER_LINE, ""));
                        RuleTargetPojo ruleTargetPojo = new RuleTargetPojo();
                        ruleTargetPojo.setFormId(targetFormId);
                        ruleTargetPojo.setLinkBusinessType(targetBusinessType);
                        Map<String, FieldAttrEntity> subExplainMap = thisSubExplainMap.get(list[2]).get(list[3]);
                        value = getValue(list[4], subExplainMap, null, targetField, workOrderFormId, ruleTargetPojo, XbbRefTypeEnum.WORK_ORDER.getCode());
                    } else {
                        Long formId = Long.valueOf(list[2]);
                        RuleTargetPojo ruleTargetPojo = new RuleTargetPojo();
                        ruleTargetPojo.setLinkBusinessType(targetBusinessType);
                        ruleTargetPojo.setFormId(targetFormId);
                        Map<String, FieldAttrEntity> subExplainMap = thisSubExplainMap.get(list[2]).get(list[3]);
                        PaasFormEntity paasFormEntity = formMap.get(formId);
                        value = getValue(list[4], subExplainMap, null, targetField, formId, ruleTargetPojo, paasFormEntity.getBusinessType());

                    }
                } else if (formulaStr.contains("user.")) {
                    value = formulaStr.replace("user.", "").replaceAll("[\\{\\}]", "");
                } else if (formulaStr.contains("dept.")) {
                    value = formulaStr.replace("dept.", "").replaceAll("[\\{\\}]", "");
                } else if (WorkflowUtil.validateFormula(list, formulaStr)){
                    if (formulaStr.contains(XbbRefTypeEnum.WORK_ORDER.getAlias())) {
                        Long workOrderFormId = Long.valueOf(list[2].replace(XbbRefTypeEnum.WORK_ORDER.getAlias() + StringConstant.UNDER_LINE, ""));
                        Map<String, FieldAttrEntity> thisExplainMap = workOrderFormFieldMap.get(workOrderFormId);
                        RuleTargetPojo ruleTargetPojo = new RuleTargetPojo();
                        ruleTargetPojo.setLinkBusinessType(targetBusinessType);
                        ruleTargetPojo.setFormId(targetFormId);
                        value = getValue(list[3], thisExplainMap, null, targetField, workOrderFormId, ruleTargetPojo, XbbRefTypeEnum.WORK_ORDER.getCode());
                    } else {
                        Long formId = Long.valueOf(list[2]);
                        Map<String, FieldAttrEntity> thisExplainMap = explainMap.get(formId);
                        RuleTargetPojo ruleTargetPojo = new RuleTargetPojo();
                        ruleTargetPojo.setLinkBusinessType(targetBusinessType);
                        ruleTargetPojo.setFormId(targetFormId);
                        PaasFormEntity paasFormEntity = formMap.get(formId);
                        value = getValue(list[3], thisExplainMap, null, targetField, formId, ruleTargetPojo, paasFormEntity.getBusinessType());

                    }
                }
                formula = formula.replace(formulaStr, value.toString());
            }
            Object result = validateDataType(formula, workflowValidateFormulaDTO.getFieldType());
            validateFormulaVO.setResult(result);
            return validateFormulaVO;
        } catch (XbbException e) {
            throw e;
        } catch (Exception e) {
            LOGGER.error("formulaServiceImpl.workflowValidate 出错：", e);
            throw new XbbException(SystemErrorCodeEnum.API_ERROR_100001);
        }
    }


    private Object validateDataType(String formula, Integer fieldType) throws XbbException {
        Object result = functionService.expressRun(formula, new HashMap<>(PaasConstant.DEFAULT_INITIAL_CAPACITY));
        FieldTypeEnum fieldTypeEnum = FieldTypeEnum.getFieldTypeEnum(fieldType);
        switch (fieldTypeEnum) {
            case TEXT:
            case TEXTAREA:
            case COMBO:
            case RADIO_GROUP:
                if (result instanceof List || result instanceof Map) {
                    throw new XbbException(ProErrorCodeEnum.API_ERROR_260016);
                }
                break;
            case USER:
                String user = JSON.toJSONString(result);
                if (RegexUtil.squareBrackets(user)) {
                    try {
                        List<String> userList = JSON.parseArray(user, String.class);
                        if (CollectionsUtil.isNotEmpty(userList)) {
                            result = userList.get(0);
                        }
                    } catch (Exception e) {
                        throw new XbbException(ProErrorCodeEnum.API_ERROR_260016);
                    }
                } else if (!RegexUtil.isInteger(result.toString())) {
                    throw new XbbException(ProErrorCodeEnum.API_ERROR_260016);
                }
                break;
            case DEPT:
            case LINK_DATA:
                if (!RegexUtil.isInteger(result.toString())) {
                    throw new XbbException(ProErrorCodeEnum.API_ERROR_260016);
                }
                break;
            case LINK_DATA_MULTI:
                // 目标字段是管理按数据多选的时候，当前字段可以是关联数据或者关联数据多选
                // 当前字段是关联数据时对应的result是数字，当前字段是关联数据多选时result是数组
                if (!RegexUtil.isInteger(result.toString())) {
                    try {
                        JSON.parseArray(JSON.toJSONString(result), Long.class);
                    } catch (Exception e) {
                        throw new XbbException(ProErrorCodeEnum.API_ERROR_260016);
                    }
                }
                break;
            case ADDRESS:
                if (result instanceof String && !result.toString().contains(BusinessConstant.PROVINCE)) {
                    JSONObject address = GaodeGeoHelper.geo(result.toString(), "");
                    if (Objects.isNull(address)) {
                        throw new XbbException(SystemErrorCodeEnum.API_ERROR_100080);
                    }
                } else {
                    JSONObject address = JSON.parseObject(result.toString());
                    if (!address.containsKey(BusinessConstant.PROVINCE) && !address.containsKey(BusinessConstant.CITY)
                            && !address.containsKey(BusinessConstant.DISTRICT) && !address.containsKey(BusinessConstant.ADDRESS)) {
                        throw new XbbException(ProErrorCodeEnum.API_ERROR_260016);
                    }
                }
                break;
            case COMBO_CHECK:
            case CHECKBOX_GROUP:
            case IMAGE:
            case USER_GROUP:
                try {
                    JSON.parseArray(JSON.toJSONString(result), String.class);
                } catch (Exception e) {
                    throw new XbbException(ProErrorCodeEnum.API_ERROR_260016);
                }
                break;
            case DEPT_GROUP:
                try {
                    JSON.parseArray(JSON.toJSONString(result), Long.class);
                } catch (Exception e) {
                    throw new XbbException(ProErrorCodeEnum.API_ERROR_260016);
                }
                break;
            case DATETIME:
                if (!(result instanceof Long) && !(result instanceof Integer) && result.toString().length() != 10) {
                    throw new XbbException(ProErrorCodeEnum.API_ERROR_260016);
                }
                break;
            case NUM:
                if (!(result instanceof Number) && !RegexUtil.isNumber(result.toString())) {
                    throw new XbbException(ProErrorCodeEnum.API_ERROR_260016);
                }
                break;
            default:
                break;
        }
        return result;
    }

    private Object getValue(String attr, Map<String, FieldAttrEntity> explainMap, Map<String, FieldAttrEntity> subExplainMap, FieldAttrEntity targetField,
                            Long formId, RuleTargetPojo ruleTargetPojo, Integer businessType) throws XbbException {
        Object value;
        if (attr.contains(FieldTypeEnum.SUB_FORM.getEsalias())) {
            List<String> thisFieldList = ExplainUtil.getAttrByPoint(attr);
            attr = thisFieldList.get(0);
            String subAttr = thisFieldList.get(1);
            if (Objects.isNull(subExplainMap) || subExplainMap.isEmpty()) {
                FieldAttrEntity fieldAttrEntity = explainMap.get(attr);
                subExplainMap = ExplainUtil.getExplainMapByList(fieldAttrEntity.getSubForm().getItems());
            }
            FieldAttrEntity fieldAttrEntity = subExplainMap.get(subAttr);
            if (Objects.isNull(fieldAttrEntity)) {
                throw new XbbException(SystemErrorCodeEnum.API_ERROR_100001, MessageConstant.FORM_EXPLAIN_NOT_EXIST);
            }
            ConditionListHelp.validateTheForm(targetField, fieldAttrEntity, formId, ruleTargetPojo.getFormId(), ruleTargetPojo.getLinkBusinessType(), businessType);
            value = getDataByFieldType(fieldAttrEntity);
        } else {
            FieldAttrEntity fieldAttrEntity = explainMap.get(attr);
            if (Objects.isNull(fieldAttrEntity)) {
                throw new XbbException(SystemErrorCodeEnum.API_ERROR_100001, MessageConstant.FORM_EXPLAIN_NOT_EXIST);
            }
            ConditionListHelp.validateTheForm(targetField, fieldAttrEntity, formId, ruleTargetPojo.getFormId(), ruleTargetPojo.getLinkBusinessType(), businessType);
            value = getDataByFieldType(fieldAttrEntity);
        }
        return value;
    }

    public Object getDataByFieldType(FieldAttrEntity fieldAttrEntity) throws XbbException {
        Object value = null;
        Integer fieldType = fieldAttrEntity.getFieldType();
        FieldTypeEnum fieldTypeEnum = FieldTypeEnum.getFieldTypeEnum(fieldType);
        switch (fieldTypeEnum) {
            case RADIO_GROUP:
            case COMBO:
                value = "\""+ "测试" + "\"";
                break;
            case CHECKBOX_GROUP:
            case COMBO_CHECK:
                List<String> valueList = new ArrayList<>();
                valueList.add("测试1");
                valueList.add("测试2");
                value = JSON.toJSONString(valueList);
                break;
            case ADDRESS:
                JSONObject addressJson = new JSONObject();
                addressJson.put(BusinessConstant.PROVINCE, "浙江省");
                addressJson.put(BusinessConstant.CITY, "杭州市");
                addressJson.put(BusinessConstant.DISTRICT, "滨江区");
                addressJson.put(BusinessConstant.ADDRESS, "滨盛路银丰大厦");
                value = JSON.toJSONString(addressJson);
                break;
            case TEXT:
                value = "\"测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试\"";
                break;
            case TEXTAREA:
                value = "\""+ "测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试" + "\"";
                break;
            case DATETIME:
                value = JSON.toJSONString(DateTimeUtil.getInt());
                break;
            case DATAID:
            case LINK_DATA:
                value = "\"123\"";
                break;
            case NUM:
                // DIVIDE等除法函数，被除数相减为0
                value = 123.11155;
                break;
            case USER:
                value = "\"1\"";
                break;
            case DEPT:
                value = "\"1\"";
                break;
            case USER_GROUP:
            case OWNERID:
            case IMAGE:
                List<String> userList = new ArrayList<>();
                userList.add("1");
                userList.add("2");
                value = JSON.toJSONString(userList);
                break;
            case DEPT_GROUP:
            case LINK_DATA_MULTI:
                List<Long> deptList = new ArrayList<>();
                deptList.add(1L);
                deptList.add(2L);
                value = JSON.toJSONString(deptList);
                break;
            default:
                value = "\"\"";
                break;
        }
        return value;
    }
}
